package com.huawei;

import java.util.*;

/**
 * Created by Z-hong on 2024/7/2.
 */

public class HJ8 {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
        for(int j=0;j<i;j++) {
            int key = sc.nextInt();
            int value = sc.nextInt();
            if (map.containsKey(key)) {
                int temp = map.get(key);
                map.put(key, temp + value);
            } else {
                map.put(key, value);
            }
        }

        List<Map.Entry<Integer, Integer>> entries = new ArrayList<>(map.entrySet());
        Collections.sort(entries, new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                return o1.getKey().compareTo(o2.getKey()); // 按照value的值进行排序
            }
        });


        for (Map.Entry<Integer, Integer> entry : entries) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }


    }
}
